#!/usr/bin/python
# GM_distinction.py
'''Computes the change in apparent magnitude for all stars at each location of the grid due to extinction and distance modulus.

As these two effects act in a very similar manner, and are the same for all stars at a given location, it's legit to bundle them together as a single equation.'''

import numpy

def distinction(simpars, phypars):
    '''Calculates the change in apparent magnitude due to distance modulus and extinction.
    
    As the form of this effect is something like a + b*x, where a and b are known at any point but x is a universal but unknown quantity, this function simply calculates the known quantities at every point.  It is left to another function to fit the remaining quantity.'''
    for i in simpars:
        cmd = "%s = simpars['%s']" % (i,i)
        exec cmd
    for i in phypars:
        cmd = "%s = phypars['%s']" % (i,i)
        exec cmd
    # Distance modulus
    DistMod = 5*numpy.log10(d/10.)
    # Extinction (up to a constant)
    ExtMod = 1 - numpy.exp(-z/hdz)
    ExtMod = numpy.divide( ExtMod, numpy.sin(ba)[numpy.newaxis,:] )
    return (DistMod, ExtMod)
